package org.opu.vcforms.transform_t2d.util.smart_xml;

import org.xml.sax.Attributes;

public class OpenTag implements XmlPart {

    /** For example: {@code w:tbl} */
    final String qName;
    /** For example: {@code tbl} */
    final String simpleName;
    final Attributes atrbts;

    public OpenTag(String simpleName, String qName, Attributes attributes) {
        this.qName = qName;
        this.simpleName = simpleName;
        this.atrbts = attributes;
    }

    @Override
    public String getText() {
        StringBuilder str = new StringBuilder();
        str.append('<').append(qName);
        for (int i = 0; i < atrbts.getLength(); i++) {
            str.append(' ').append(atrbts.getQName(i)).append("=\"")
                    .append(atrbts.getValue(i)).append('"');
        }
        str.append('>');
        return str.toString();
    }

    public String getClose(){
         return "</" + qName + '>';
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }

        final OpenTag other = (OpenTag) obj;
        if ((this.qName == null) ? (other.qName != null) : !this.qName.equals(other.qName)) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + (this.qName != null ? this.qName.hashCode() : 0);
        return hash;
    }
}
